﻿' Developer Express Code Central Example:
' How to customize the Edit Appointment form to show custom fields
' 
' This example illustrates the use of a custom form to enable the end-user to edit
' custom fields. The custom form is invoked instead of the default one by handling
' the SchedulerControl.EditAppointmentFormShowing
' (ms-help://DevExpress.NETv8.2/DevExpress.XtraScheduler/DevExpressXtraSchedulerSchedulerControl_EditAppointmentFormShowingtopic.htm)
' event.
' 
' See also:
' For a simple application that enables you to handle custom
' fields, see the http://www.devexpress.com/scid=E2782 article.
' 
' You can find sample updates and versions for different programming languages here:
' http://www.devexpress.com/example=E152


Partial Public Class MyScheduleEditForm
    Inherits AppointmentEditForm

    Public Property WorkCodeQueryName As String = "LOV_WorkCode"


    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(ByVal control As SchedulerControl, ByVal apt As Appointment)
        MyBase.New(control, apt)
        ' Required to initialize controls that represent custom fields
        InitializeComponent()
        '
        'On construit un array pour positionner les label a la bonne position.
        For i As Integer = 1 To 999
            labelByOrderByIdInt.Add(String.Empty)
            labelByQueryOrder.Add(String.Empty)
        Next
    End Sub

    Protected Overrides Sub UpdateForm()
        MyBase.UpdateForm()
        'AddHandler edtLabel.SelectedValueChanged, AddressOf titi
    End Sub

    Protected Overrides Sub OnOkButton()
        MyBase.OnOkButton()
        Me.Controller.IsAppointmentChanged()
    End Sub

    Protected Overrides Sub OnDeleteButton()
        MyBase.OnDeleteButton()
    End Sub

    Protected Overrides Sub OnRecurrenceButton()
        MyBase.OnRecurrenceButton()
    End Sub

    Protected Overrides Function CreateController(ByVal control As SchedulerControl, ByVal apt As Appointment) As AppointmentFormController
        Return New MyScheduleController(control, apt)
    End Function

    Protected Overrides Sub UpdateCustomFieldsControls()
        MyBase.UpdateCustomFieldsControls()
        TxtHrs.EditValue = (CType(MyBase.Controller, MyScheduleController)).CustomHrs
    End Sub


    Protected Overrides Sub edtLabel_EditValueChanged(sender As Object, e As EventArgs)
        'Selon la position dans le ComboBox on retrouve le LabelInt
        Me.Controller.LabelId = CType(labelByQueryOrder.Item(edtLabel.SelectedIndex), LabelColor).Labelint
    End Sub

   
    Private Sub TxtHrs_EditValueChanged(sender As Object, e As EventArgs) Handles TxtHrs.EditValueChanged
        'Selon la position dans le ComboBox on retrouve le LabelInt
        CType(MyBase.Controller, MyScheduleController).CustomHrs = CType(sender, TextEdit).EditValue
    End Sub

    Private Sub mslTimeSheetHourWorkCode_EditValueChanged(sender As Object, e As EventArgs) Handles mslTimeSheetHourWorkCode.EditValueChanged
        Dim tmpGuid As Guid
        If mslTimeSheetHourWorkCode.EditValue IsNot Nothing AndAlso Guid.TryParse(mslTimeSheetHourWorkCode.EditValue.ToString, tmpGuid) Then
            CType(MyBase.Controller, MyScheduleController).CustomWorkCodeId = tmpGuid
        Else
            CType(MyBase.Controller, MyScheduleController).CustomWorkCodeId = Nothing
        End If

    End Sub

    Private Sub MyScheduleEditForm_Load(sender As Object, e As EventArgs) Handles Me.Load
        'mslTimeSheetHourWorkCode.Enabled = Not LockGroup

        mslTimeSheetHourWorkCode.QueryName = WorkCodeQueryName
        mslTimeSheetHourWorkCode.InitMetaQuery()
        mslTimeSheetHourWorkCode.EditValue = (CType(MyBase.Controller, MyScheduleController)).CustomWorkCodeId
        mslTimeSheetHourWorkCode.Refresh()

    End Sub
End Class
